<template>
	<div class="list-wrapper">
		<div class="list-top">
			<el-form :inline="true">
				<el-form-item label="课程类型">
					<el-select v-model="type" placeholder="课程类型" clearable @change="search">
						<el-option v-for="item in typeLists" :key="item.id" :label="item.name" :value="item.id"></el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<!--<el-button type="primary">下载</el-button>-->
		</div>
		<table class="list-table" border="0" cellspacing="0" cellpadding="0">
			<thead>
				<tr>
					<th class="img-text">
						<router-link to="add">
							<img src="../../img/add.png" alt="">
						</router-link>
					</th>
					<th>课程编号</th>
					<th>课程名称</th>
					<th>课程分级</th>
					<th>课程类型</th>
					<th>课程天数</th>
					<th>收费标准（元）</th>
					<th>标准开班人数</th>
					<th>是否使用模拟器</th>
					<th>IMO示范课程</th>
					<th>证书有效期（月）</th>
				</tr>
			</thead>
			<tbody>
				<tr v-for="item in list" :key="item.id">
					<td>
						<!--<router-link to="add">-->
							<!--<img src="../../img/edit.gif" alt="">							-->
						<!--</router-link>-->
						<img src="../../img/del.png" alt="" @click="del(item.id)">
						<router-link v-bind="{to:'detail/'+item.id}">
							<img src="../../img/detail.png" alt="">
						</router-link>
					</td>
					<td>{{item.code}}</td>
					<td>{{item.name}}</td>
					<td>{{item.rank}}</td>
					<td>{{item.type_name}}</td>
					<td>{{item.days}}</td>
					<td>{{item.standardfee}}</td>
					<td>{{item.standardnum}}</td>
					<td>{{item.simulator?'是':'否'}}</td>
					<td>{{item.imo?'是':'否'}}</td>
					<td>{{item.certificate_time}}</td>
				</tr>
			</tbody>
		</table>
		<div class="namtc-pagination">
			<el-pagination @current-change="handleCurrentChange" :current-page="page" :page-size="10" layout="total, prev, pager, next, jumper" :total="total">
			</el-pagination>
		</div>
	</div>
</template>
<script>

  export default {
    data() {
      return {
        type: '',
        typeLists: [],
        page: 1,
        total: 0,
        list: [],

      }
    },

    methods: {
      fetchData(){
        let data = {
          type: this.type,
          page: this.page
        }
        this.apiPost('Train/courseLists', data).then(res=>{
          this.list = res.list
          this.total = parseInt(res.total)
        })
      },
      getTypes(){
        this.apiPost('System/courseTypeLists').then(res=>{
          this.typeLists = res
        })
      },
      handleCurrentChange(val){
        this.page = val
        this.fetchData()
      },
      search(val) {
        this.type = val
        this.fetchData()
			},
      del(id){
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let data = {
            id: id
          }
          this.apiPost('Train/courseDelete', data).then(res=>{
            let remind = res.error?'error':'success'
            _g.toastMsg(remind, res.msg)
            if(!res.error){
              this.fetchData()
            }
          })
        }).catch(() => {

        });
      }
		},
		created() {
			this.fetchData()
			this.getTypes()

		},
	}



</script>
<style scoped>

</style>
